package web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet("/test")
public class UserAgentServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        boolean isIE = (Boolean) request.getAttribute("ie");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<h2>Hello Servlet Get</h2>");

        if (isIE) {
            out.println("<h2>IE detected</h2>");
        } else {
            out.println("Redirect to 404");
            response.sendRedirect("error.jsp");
        }

        out.println("</body>");
        out.println("</html>");

    }
}